package com.data.bobostructure.chapter1.practice;

import com.data.bobostructure.utils.SortUtils;

/**
 * Created by wangbing on 2018/3/30.
 */
//自己实现的冒泡排序
public class BubbleSort {
    public static  void BubbleSort(Comparable [] arr){
        int len = arr.length;
        /**
         * 默认从小到大排序
         */
    for (int j=0;j<len;j++){

        for (int i=1;i<len;i++){
            if (arr[i].compareTo(arr[i-1])<0){
                SortUtils.swap(arr,i,i-1);

            }
        }
    }
    }
    public static void main(String[] args) {
        Comparable[] arr = {9,8,7,6,5,4,3,11};
        BubbleSort(arr);
        for (Comparable i:
             arr) {
            System.out.println(i);
            
        }


    }
}
